<?php
/**
 *      [Haidao] (C)2013-2099 Dmibox Science and technology co., LTD.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      http://www.haidao.la
 *      tel:400-600-2042
 */
class queue_service extends service
{
	protected $entrydir = '';
	public function _initialize() {
		$this->entrydir = MODULE_PATH.'library/driver/';
		$this->notify = model('notify/notify','service');
		$this->queue = model('notify/queue','table');
	}
	public function config($name){
		$_config = $this->notify->get_fech_enable_code($name);
		if(FALSE === $_config || empty($_config['configs']) || $_config['enabled']==0)die('通知方式未安装或未开启');
		$class_name = $name;
		$class_file = $this->entrydir.$name.'/'.$name.'.class.php';
		if (!file_exists($class_file)) die('驱动不存在');
		require_once($class_file);
		$this->queue = new $class_name($_config['configs']);
		return $this->queue;
	}
	
	public function add_queue($params){
		return $this->queue->add($params);
	}
	
	public function __call($method_name, $method_args){
		if (method_exists($this, $method_name))
			return call_user_func_array(array(& $this, $method_name), $method_args);
		elseif (
			!empty($this->queue)
			&& method_exists($this->queue, $method_name)
		) 
		return call_user_func_array(array(& $this->queue, $method_name), $method_args);
	}
	
}